//
//  YGArticleBLL.m
//  yuanshangyiliao
//
//  Created by icholab on 2021/5/3.
//

#import "YGArticleBLL.h"
#import "CNHTTPManager.h"
#import <MJExtension/MJExtension.h>

@implementation YGArticleBLL

+ (void)requestArticleWithID:(NSString*)typeId
                        name:(NSString *)name
                        page:(NSInteger)page
                        Success:(void (^)(YGArticleListModel *model))success
fail:(void (^)(NSError *error))fail{
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [dic fa_setObjectSafe:typeId forKey:@"typeId"];
    [dic fa_setObjectSafe:@"" forKey:@"name"];
    [dic fa_setObjectSafe:@(page) forKey:@"page"];
    [dic fa_setObjectSafe:@(30) forKey:@"rows"];

    [[CNHTTPManager shared] GET:YG_SCIENCE_CENTER_ARTICLE_LIST parameters:dic success:^(id responeObj) {
        NSDictionary *data = [responeObj objectForKey:@"data"];
        YGArticleListModel *model =  [YGArticleListModel mj_objectWithKeyValues:data];
        if (success) {
            success(model);
        }
    } failure:^(NSError *error, NSString *errorDes) {
        if (fail) {
            fail(error);
        }
    }];
}


+ (void)requestSubscribeithID:(NSString*)typeId
                        Success:(void (^)(void))success
                        fail:(void (^)(NSError *error))fail{
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [dic fa_setObjectSafe:typeId forKey:@"articleTypeId"];
   

    [[CNHTTPManager shared] GET:YG_SCIENCE_CENTER_ARTICLE_TYPE_SUBSCRIBE parameters:dic success:^(id responeObj) {
        if (success) {
            success();
        }
    } failure:^(NSError *error, NSString *errorDes) {
        if (fail) {
            fail(error);
        }
    }];
}

#pragma -科普中心-科普中心文章详情
+ (void)requestScienceCenterArticleDetailWithId:(NSString *)Id Success:(void (^)(YGScienceCenterArticleDetailModel * model))success fail:(void (^)(NSError * error))fail{
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [dic fa_setObjectSafe:Id forKey:@"id"];
    [[CNHTTPManager shared]GET:YG_SCIENCE_CENTER_ARTICLE_DETAIL parameters:dic success:^(id responeObj) {
        
        NSDictionary *data = [responeObj objectForKey:@"data"];
        YGScienceCenterArticleDetailModel *model = [[YGScienceCenterArticleDetailModel alloc]initWithDictionary:data error:nil];
        if(success){
            success(model);
        }
        } failure:^(NSError *error, NSString *errorDes) {
            if(fail){
                fail(error);
            }
        }];
}


@end
